﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aliyun.OSS;

namespace OSSImport
{
    class Program
    {
        static string accessKeyId = Config.AccessKeyId;
        static string accessKeySecret = Config.AccessKeySecret;
        static string endpoint = Config.Endpoint;
        private static string bucketName = Config.BucketName;
        static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret);
        static void Main(string[] args)
        {
            
            DirectoryInfo dir=new DirectoryInfo("D:\\Host\\weapp.711688.net.cn\\images");
            UploadDir(dir);
            Console.ReadLine();

        }

        static void UploadDir(DirectoryInfo dir)
        {
            var files = dir.GetFiles("*.*");
            foreach (var file in files)
            {
                var name = file.FullName;
                var key = file.FullName.Remove(0, "D:\\Host\\weapp.711688.net.cn\\images".Length - 6).Replace("\\", "/");
                Console.WriteLine(name);
                client.PutObject(bucketName, key, name);


            }
            if (dir.GetDirectories().Length > 0)
            {
                foreach (var cdir in dir.GetDirectories())
                {
                    UploadDir(cdir);
                }
            }
            
        }
    }
}
